c642502516d44eb24c364208b79a2e5d4793ced1,applications/party/src/org/ofbiz/party/party/PartyServices.java,PartyServices,createPartyGroup,#DispatchContext#Map#,331
Before Change
partyId = delegator.getNextSeqId("Party");
} catch (IllegalArgumentException e) {
errMsg = UtilProperties.getMessage(resource,"partyservices.could_not_create_party_group_generation_failure", locale);
return ServiceUtil.returnError(errMsg);
}
} else {
// if specified partyId starts with a number, return an error
if (partyId.matches("\\d+")) {
errMsg = UtilProperties.getMessage(resource,"partyservices.could_not_create_party_ID_digit", locale);
return ServiceUtil.returnError(errMsg);
}
}
try {
// check to see if party object exists, if so make sure it is PARTY_GROUP type party
GenericValue party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId));
GenericValue partyGroupPartyType = delegator.findByPrimaryKeyCache("PartyType", UtilMisc.toMap("partyTypeId", "PARTY_GROUP"));
if (partyGroupPartyType == null) {
errMsg = UtilProperties.getMessage(resource,"partyservices.party_type_not_found_in_database_cannot_create_party_group", locale);
return ServiceUtil.returnError(errMsg);
}
if (party != null) {
GenericValue partyType = party.getRelatedOneCache("PartyType");
if (!EntityTypeUtil.isType(partyType, partyGroupPartyType)) {
errMsg = UtilProperties.getMessage(resource,"partyservices.cannot_create_party_group_already_exists_not_PARTY_GROUP_type", locale);
return ServiceUtil.returnError(errMsg);
}
} else {
// create a party if one doesn't already exist
String partyTypeId = "PARTY_GROUP";
if (UtilValidate.isNotEmpty(context.get("partyTypeId"))) {
GenericValue desiredPartyType = delegator.findByPrimaryKeyCache("PartyType", UtilMisc.toMap("partyTypeId", context.get("partyTypeId")));
if (desiredPartyType != null && EntityTypeUtil.isType(desiredPartyType, partyGroupPartyType)) {
partyTypeId = desiredPartyType.getString("partyTypeId");
} else {
return ServiceUtil.returnError("The specified partyTypeId [" + context.get("partyTypeId") + "] could not be found or is not a sub-type of PARTY_GROUP");
}
}
Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", partyTypeId, "createdDate", now, "lastModifiedDate", now);
if (userLogin != null) {
newPartyMap.put("createdByUserLogin", userLogin.get("userLoginId"));
newPartyMap.put("lastModifiedByUserLogin", userLogin.get("userLoginId"));
}
String statusId = (String) context.get("statusId");
party = delegator.makeValue("Party", newPartyMap);
party.setNonPKFields(context);
if (statusId == null) {
statusId = "PARTY_ENABLED";
}
party.set("statusId", statusId);
party.create();
// create the status history
GenericValue partyStat = delegator.makeValue("PartyStatus",
UtilMisc.toMap("partyId", partyId, "statusId", statusId, "statusDate", now));
partyStat.create();
}
GenericValue partyGroup = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", partyId));
if (partyGroup != null) {
errMsg = UtilProperties.getMessage(resource,"partyservices.cannot_create_party_group_already_exists", locale);
return ServiceUtil.returnError(errMsg);
}
partyGroup = delegator.makeValue("PartyGroup", UtilMisc.toMap("partyId", partyId));
partyGroup.setNonPKFields(context);
partyGroup.create();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage());
errMsg = UtilProperties.getMessage(resource,"partyservices.data_source_error_adding_party_group", messageMap, locale);
return ServiceUtil.returnError(errMsg);
}
result.put("partyId", partyId);
After Change
try {
partyId = delegator.getNextSeqId("Party");
} catch (IllegalArgumentException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.could_not_create_party_group_generation_failure", locale));
}
} else {
// if specified partyId starts with a number, return an error
if (partyId.matches("\\d+")) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.could_not_create_party_ID_digit", locale));
}
}
try {
// check to see if party object exists, if so make sure it is PARTY_GROUP type party
GenericValue party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId));
GenericValue partyGroupPartyType = delegator.findByPrimaryKeyCache("PartyType", UtilMisc.toMap("partyTypeId", "PARTY_GROUP"));
if (partyGroupPartyType == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.partyservices.party_type_not_found_in_database_cannot_create_party_group", locale));
}
if (party != null) {
GenericValue partyType = party.getRelatedOneCache("PartyType");
if (!EntityTypeUtil.isType(partyType, partyGroupPartyType)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.partyservices.cannot_create_party_group_already_exists_not_PARTY_GROUP_type", locale));
}
} else {
// create a party if one doesn't already exist
String partyTypeId = "PARTY_GROUP";
if (UtilValidate.isNotEmpty(context.get("partyTypeId"))) {
GenericValue desiredPartyType = delegator.findByPrimaryKeyCache("PartyType", UtilMisc.toMap("partyTypeId", context.get("partyTypeId")));
if (desiredPartyType != null && EntityTypeUtil.isType(desiredPartyType, partyGroupPartyType)) {
partyTypeId = desiredPartyType.getString("partyTypeId");
} else {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"PartyPartyTypeIdNotFound", UtilMisc.toMap("partyTypeId", context.get("partyTypeId")), locale));
}
}
Map<String, Object> newPartyMap = UtilMisc.toMap("partyId", partyId, "partyTypeId", partyTypeId, "createdDate", now, "lastModifiedDate", now);
if (userLogin != null) {
newPartyMap.put("createdByUserLogin", userLogin.get("userLoginId"));
newPartyMap.put("lastModifiedByUserLogin", userLogin.get("userLoginId"));
}
String statusId = (String) context.get("statusId");
party = delegator.makeValue("Party", newPartyMap);
party.setNonPKFields(context);
if (statusId == null) {
statusId = "PARTY_ENABLED";
}
party.set("statusId", statusId);
party.create();
// create the status history
GenericValue partyStat = delegator.makeValue("PartyStatus",
UtilMisc.toMap("partyId", partyId, "statusId", statusId, "statusDate", now));
partyStat.create();
}
GenericValue partyGroup = delegator.findByPrimaryKey("PartyGroup", UtilMisc.toMap("partyId", partyId));
if (partyGroup != null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.cannot_create_party_group_already_exists", locale));
}
partyGroup = delegator.makeValue("PartyGroup", UtilMisc.toMap("partyId", partyId));
partyGroup.setNonPKFields(context);
partyGroup.create();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
"partyservices.data_source_error_adding_party_group",
UtilMisc.toMap("errMessage", e.getMessage()), locale));
}
result.put("partyId", partyId);